package com.ruoyi.face.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.ruoyi.face.util.ImageUtil;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

public class Member {
    @JsonProperty(value = "recognition_type")
    private String recognitionType;

    private Long id;

    @JsonProperty(value = "is_admin")
    private boolean isAdmin;

    @JsonProperty(value = "person_name")
    private String personName;

    @JsonProperty(value = "group_list")
    private List<String> groupList;

    @JsonProperty(value = "face_list")
    private List<FaceData> faceList;

    /**
     * 特征值信息
     */
    @JsonProperty(value = "feature_list")
    private List<FaceData> featureList;

    @JsonProperty(value = "check_feature_status")
    private Integer status;

    @JsonProperty(value = "phone_num")
    private String phone;

    public String getRecognitionType() {
        return recognitionType;
    }

    public void setRecognitionType(String recognitionType) {
        this.recognitionType = recognitionType;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public boolean getIsAdmin() {
        return isAdmin;
    }

    public void setIsAdmin(boolean admin) {
        isAdmin = admin;
    }

    public String getPersonName() {
        return personName;
    }

    public void setPersonName(String personName) {
        this.personName = personName;
    }

    public List<String> getGroupList() {
        return groupList;
    }

    public List<FaceData> getFaceList() {
        return faceList;
    }

    public void setFaceList(List<FaceData> faceList) {
        this.faceList = faceList;
    }

    public void setGroupList(List<String> groupList) {
        this.groupList = groupList;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public List<FaceData> getFeatureList() {
        return featureList;
    }

    public void setFeatureList(List<FaceData> featureList) {
        this.featureList = featureList;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public void addImage(ImageType imageType, byte[] file) {
        if (faceList == null) {
            faceList = new ArrayList<>();
        }
        FaceData data = new FaceData();
        data.setIdx(imageType.getCode());
        byte[] inch = ImageUtil.Resize2Inch(file);
        data.setData(Base64.getEncoder().encodeToString(inch));

        faceList.add(data);
    }

    @Override
    public String toString() {
        return "Member{" +
                "recognitionType='" + recognitionType + '\'' +
                ", id=" + id +
                ", isAdmin=" + isAdmin +
                ", personName='" + personName + '\'' +
                ", groupList=" + groupList +
                ", faceList=" + faceList +
                ", featureList=" + featureList +
                ", status=" + status +
                '}';
    }

    public static class FaceData {

        private Integer idx;

        private String data;

        public Integer getIdx() {
            return idx;
        }

        public void setIdx(Integer idx) {
            this.idx = idx;
        }

        public String getData() {
            return data;
        }

        public void setData(String data) {
            this.data = data;
        }

        @Override
        public String toString() {
            return "FaceData{" +
                    "idx=" + idx +
                    ", data='" + data + '\'' +
                    '}';
        }
    }
}
